import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType}

val nameStr="live_dm"
val scalaVersionStr="2.13.5"

name := nameStr

version := "0.1"

scalaVersion := scalaVersionStr

lazy val server = (project in file("server")).settings(commonSettings).settings(
  scalaJSProjects := Seq(client),
  version := "1.0",
  name := nameStr,
  Assets / pipelineStages := Seq(scalaJSPipeline),
  pipelineStages := Seq(digest, gzip),
  Compile / compile := ((Compile / compile) dependsOn scalaJSPipeline).value,
  libraryDependencies ++= Seq(
    "com.vmunier" %% "scalajs-scripts" % "1.2.0",
    guice,
    specs2 % Test,
    "com.typesafe.play" %% "play-slick" % "4.0.2",
    "com.typesafe.slick" %% "slick-codegen" % "3.3.2",
    "com.github.tototoshi" %% "slick-joda-mapper" % "2.4.1",
    "commons-io" % "commons-io" % "2.5",
    "org.apache.poi" % "poi-ooxml" % "3.15",
    "com.github.jurajburian" %% "mailer" % "1.2.4",
    "org.apache.commons" % "commons-math3" % "3.6.1",
    "com.typesafe.play" %% "play-joda-forms" % "2.7.3",
    "com.h2database" % "h2" % "1.4.199",
    "org.apache.xmlgraphics" % "batik-codec" % "1.10",
    "org.typelevel" %% "cats-core" % "2.0.0",
    "org.scala-lang.modules" %% "scala-parallel-collections" % "0.2.0",
    "org.apache.commons" % "commons-lang3" % "3.6",
    "io.github.alexarchambault" %% "data-class" % "0.2.5",
    "com.lihaoyi" %% "requests" % "0.6.9"
  )
).enablePlugins(PlayScala, LauncherJarPlugin).dependsOn(sharedJvm)

lazy val client = (project in file("client")).settings(commonSettings).settings(
  scalaJSUseMainModuleInitializer := false,
  resolvers += "jitpack" at "https://jitpack.io",
  libraryDependencies ++= Seq(
    "com.lihaoyi" %%% "scalatags" % "0.11.1"
  )

).enablePlugins(ScalaJSPlugin, ScalaJSWeb).dependsOn(sharedJs)

lazy val shared = crossProject(JSPlatform, JVMPlatform)
  .crossType(CrossType.Pure)
  .in(file("shared"))
  .settings(commonSettings).settings(
  scalacOptions ++= {
    Seq("-Ymacro-annotations")
  },
  libraryDependencies ++= Seq(
    "com.chuusai" %% "shapeless" % "2.3.3",
    "io.github.alexarchambault" %% "data-class" % "0.2.5",
    "com.github.alexarchambault" %%% "argonaut-shapeless_6.3" % "1.3.0"

  )
)
lazy val sharedJvm = shared.jvm
lazy val sharedJs = shared.js

lazy val commonSettings = Seq(
  scalaVersion := scalaVersionStr
)

onLoad in Global := (onLoad in Global).value andThen { s: State => "project server" :: s }
